<?php
/***  DOCUMENTATION LAYER

Ceo Sample Unit Test

Last Update: Aug 2007
  
DESCRIPTION
  this file provides a template for other simple unit tests.
  
NOTES
  $test_root dynamically sets root in order to keep tests working after
  they are moved to the __REPOSITORY directory
    
______________________________________________________________________________*/

$_tx0 = microtime();
$test_root = ( strpos(dirname(__FILE__), 'repository') === false ) ? '' : '../';


// Test Name
$test_name = 'sample test';

// Include Files
require_once($test_root . '../php_ceo/framework.class.php');

// Configure Test
$debug = 1;


// Test Procedure
  $root = $test_root . '../php_ceo/';
  require_once($root . 'ext/input/element.class.php');
  $target = $root . 'ext/input/input_text.class.php';
  
  require_once( $root . 'fso.class.php' );
  $Fso = new CeoFso(0);
  print "<h2 style='margin:0 0 10px; color:#999; font-family:sans-serif; font-weight:normal;'>we'll be parsing <b style='color:#900;'>$target</b></h2>";
  $f = $Fso->read($target);
  
  // cx the object for dumping later
  require_once($target);
  $Object = new CeoBase();
  
  // functions
  $f1 = '\n\s*function\s+';
  $f2 = '([^\(]+)\(';
  $f3 = '([^\)]*)\)';
  $f4 = '[^\n]*\n';
  $re_fx = "%{$f1}({$f2}{$f3}){$f4}%i";
  
  // vars
  $f1 = '\n\s*var\s+';
  $f2 = '\$[^\s]+';
  $f3 = '\s';
  $re_var = "%{$f1}({$f2}{$f3})%i";
  
  // rip vars
  print '<h3 id="props">properties</h3>';
  if ( preg_match_all($re_var, $f, $_MATCH) )
  {
    $Fso->print_d("var regex successful [$re_var]", 'green');    
    foreach ( $_MATCH[1] as $_Fx ) $Fso->print_d($_Fx . '<br/>', '#333');
    #$Fso->print_d('<pre>'.print_r($_MATCH[1],1).'</pre>', 'blue');
    #$Fso->print_d($Fso->print_r($_MATCH));
  }
  else
  {
    $Fso->print_d("regex [$re_var] failed", 'magenta');
  }
  
  print "<hr />";
  
  // rip functions
  print '<h3 id="methods">methods</h3>';
  if ( preg_match_all($re_fx, $f, $_MATCH) )
  {
    $Fso->print_d("fx regex successful [$re_fx]", 'green');
    foreach ( $_MATCH[1] as $_Fx ) $Fso->print_d($_Fx . '<br/>', '#333');
    #$Fso->print_d('<pre>'.print_r($_MATCH[1],1).'</pre>', 'blue');
    #$Fso->print_d($Fso->print_r($_MATCH));
  }
  else
  {
    $Fso->print_d("regex [$re_fx] failed", 'magenta');
  }
  
  // dump object
  print '<pre style="background:#ccc;">';
  $Object->dump();
  print '</pre>';


// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
echo "<h6>test '$test_name' complete in $stx s</h6>";
?>
